import { Init } from 'src/common/entities/init.entity';

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
import { IsNotEmpty } from 'class-validator';
import { GoodsCategory } from './goodsCategory.entity';
import { Exclude } from 'class-transformer';

@Entity({
  comment: '商品表',
})
export class Goods extends Init {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    type: 'varchar',
    length: 255,
    comment: '商品名称',
  })
  name: string;

  @Column({
    type: 'decimal',
    precision: 10,
    scale: 2,
    comment: '商品价格',
  })
  price: number;

  @Column({
    type: 'text',
    comment: '商品描述',
    nullable: true,
  })
  description: string | null;

  @Column({
    type: 'int',
    comment: '库存数量',
    default: 0,
  })
  stock: number;

  @Column({
    type: 'varchar',
    comment: '主图',
    length: 255,
    nullable: true,
  })
  @IsNotEmpty({
    message: '主图不能为空',
  })
  mainImage: string;

  @Column({
    type: 'json',
    comment: '商品副图',
    nullable: true,
  })
  imageList: string[];

  @Column({
    type: 'int',
    comment: '商品分类id',
  })
  @IsNotEmpty({
    message: '商品分类id不能为空',
  })
  @Exclude()
  categoryId: number;
}
